﻿using AnesSystem.Models;
using AnesSystem.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.Util
{
    class QualityExport
    {

        public static List<QualityStatisticsModel> calValue(List<string> accountIdList, DateTime startTime, DateTime endTime)
        {
            List<PatientLinkModel> patientLinkList = PatientLinkService.Instance.GetFinishOperByTime(startTime, endTime);
            //getFinishOperByTime(startTime, endTime);
            Dictionary<DateTime, QualityStatisticsModel> mapNewZhiKong = new Dictionary<DateTime, QualityStatisticsModel>();
            List<PatientLinkModel> patientLinks = new List<PatientLinkModel>();
            if (null != accountIdList && accountIdList.Count() > 0)
            {
                for (int i = 0; i < patientLinkList.Count; i++)
                {
                    for (int j = 0; j < accountIdList.Count; j++)
                    {
                        if (ExportToExcel.isOperOfAllDoctor(patientLinkList[i], accountIdList[j]))
                        {
                            patientLinks.Add(patientLinkList[i]);
                        }
                    }
                }
            }
            else
            {
                patientLinks.AddRange(patientLinkList);
            }
            foreach (PatientLinkModel patientLink in patientLinks)
            {
                QualityPojoModel pojo = patientLink.QualityPojo;
                string monthTime = patientLink.Status.InRoomTime.Year.ToString() + "-" + patientLink.Status.InRoomTime.Month.ToString() + "-1";
                DateTime monthDate = Convert.ToDateTime(monthTime);
                QualityStatisticsModel mazuiZhiKongTJ = mapNewZhiKong.ContainsKey(monthDate) ? mapNewZhiKong[monthDate] : null;
                if (mazuiZhiKongTJ == null)
                {
                    mazuiZhiKongTJ = new QualityStatisticsModel();
                    mazuiZhiKongTJ.Date = monthDate;
                    mazuiZhiKongTJ.LastEditTime = new DateTime();
                    mapNewZhiKong.Add(monthDate, mazuiZhiKongTJ);
                }

                //质控信息录入计算
                if (pojo.Ywsw)
                {
                    mazuiZhiKongTJ.SiWang++;  //死亡
                    mazuiZhiKongTJ.SiWangOperList.Add(patientLink);
                }
                if (pojo.Mzksh24xsnxtzt)
                {
                    mazuiZhiKongTJ.XinTiaoStop++; //心脏骤停
                    mazuiZhiKongTJ.XinTiaoStopOperList.Add(patientLink);
                }
                if (pojo.Mzhssqx)
                {
                    mazuiZhiKongTJ.CancelShouShu++;  //手术取消
                    mazuiZhiKongTJ.CancelShouShuOperList.Add(patientLink);
                }
                if (pojo.Mzqjyzgmfy)
                {
                    mazuiZhiKongTJ.GuoMinYanZhong++;  //过敏
                    mazuiZhiKongTJ.GuoMinYanZhongOperList.Add(patientLink);
                }
                if (pojo.Zgnmzhyzsjxtbfzfs)
                {
                    mazuiZhiKongTJ.ShenJingBingFa++; //椎管内麻醉并发症
                    mazuiZhiKongTJ.ShenJingBingFaOperList.Add(patientLink);
                }
                if (pojo.Zxjmccyzbf)
                {
                    mazuiZhiKongTJ.JingMaiChuanCiBingFa++; //中心静脉穿刺并发症
                    mazuiZhiKongTJ.JingMaiChuanCiBingFaOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.Zxjmcc)
                {
                    mazuiZhiKongTJ.ZhongXinJingMaiChuanCi++; //中心静脉穿刺总数
                    mazuiZhiKongTJ.ZhongXinJingMaiChuanCiOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.Csyd)
                {
                    mazuiZhiKongTJ.ChaoShengYinDao++;
                    mazuiZhiKongTJ.ChaoShengYinDaoOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.Sygzz)
                {
                    mazuiZhiKongTJ.ShiYongShuZhuGongZuoZhan++;
                    mazuiZhiKongTJ.ShiYongShuZhuGongZuoZhanOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.Jwzl)
                {
                    mazuiZhiKongTJ.XueYeJiaWenZhiLiao++;
                    mazuiZhiKongTJ.XueYeJiaWenZhiLiaoOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.Jyzl)
                {
                    mazuiZhiKongTJ.KongZhiXingJiangYa++;
                    mazuiZhiKongTJ.KongZhiXingJiangYaOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.Teg)
                {
                    mazuiZhiKongTJ.Teg++;
                    mazuiZhiKongTJ.TegOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.PCEA)
                {
                    mazuiZhiKongTJ.Pcea++;
                    mazuiZhiKongTJ.PceaOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.PCIA)
                {
                    mazuiZhiKongTJ.Pcia++;
                    mazuiZhiKongTJ.PciaOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.WyPCA)
                {
                    mazuiZhiKongTJ.NoPca++;
                    mazuiZhiKongTJ.NoPcaOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.ComplicatedMethod.Qm && patientLink.AnesthesiaRecord.ComplicatedMethod.Zm1)
                {
                    mazuiZhiKongTJ.QuanMaXiaoGuo1++;
                    mazuiZhiKongTJ.QuanMaXiaoGuo1OperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.ComplicatedMethod.Qm && patientLink.AnesthesiaRecord.ComplicatedMethod.Zm2)
                {
                    mazuiZhiKongTJ.QuanMaXiaoGuo2++;
                    mazuiZhiKongTJ.QuanMaXiaoGuo2OperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.ComplicatedMethod.Qm && patientLink.AnesthesiaRecord.ComplicatedMethod.Zm3)
                {
                    mazuiZhiKongTJ.QuanMaXiaoGuo3++;
                    mazuiZhiKongTJ.QuanMaXiaoGuo3OperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.ComplicatedMethod.Zgnmz && patientLink.AnesthesiaRecord.ComplicatedMethod.Zm1)
                {
                    mazuiZhiKongTJ.ZhuiGuanNeiXiaoGuo1++;
                    mazuiZhiKongTJ.ZhuiGuanNeiXiaoGuo1OperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.ComplicatedMethod.Zgnmz && patientLink.AnesthesiaRecord.ComplicatedMethod.Zm2)
                {
                    mazuiZhiKongTJ.ZhuiGuanNeiXiaoGuo2++;
                    mazuiZhiKongTJ.ZhuiGuanNeiXiaoGuo2OperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.ComplicatedMethod.Zgnmz && patientLink.AnesthesiaRecord.ComplicatedMethod.Zm3)
                {
                    mazuiZhiKongTJ.ZhuiGuanNeiXiaoGuo3++;
                    mazuiZhiKongTJ.ZhuiGuanNeiXiaoGuo3OperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.ComplicatedMethod.Zgnmz && patientLink.AnesthesiaRecord.ComplicatedMethod.Zm4)
                {
                    mazuiZhiKongTJ.ZhuiGuanNeiXiaoGuo4++;
                    mazuiZhiKongTJ.ZhuiGuanNeiXiaoGuo4OperList.Add(patientLink);
                }
                if (null != patientLink.AnesthesiaRecord.Brqw && patientLink.AnesthesiaRecord.Brqw.Equals("病房"))
                {
                    mazuiZhiKongTJ.PatToBf++;
                    mazuiZhiKongTJ.PatToBfOperList.Add(patientLink);
                }
                if (null != patientLink.AnesthesiaRecord.Brqw && patientLink.AnesthesiaRecord.Brqw.Equals("PACU"))
                {
                    mazuiZhiKongTJ.PatToPacu++;
                    mazuiZhiKongTJ.PatToPacuOperList.Add(patientLink);
                }
                if (null != patientLink.AnesthesiaRecord.Brqw && patientLink.AnesthesiaRecord.Brqw.Equals("ICU"))
                {
                    mazuiZhiKongTJ.PatToIcu++;
                    mazuiZhiKongTJ.PatToIcuOperList.Add(patientLink);
                }
                if (patientLink.AnesthesiaRecord.Dmcc)
                {
                    mazuiZhiKongTJ.DongMaiChuanCi++; //动脉穿刺总数
                    mazuiZhiKongTJ.DongMaiChuanCiOperList.Add(patientLink);
                }
                try
                {
                    string trueAge;
                    string age = patientLink.Patient.Nl;
                    if (null != age && age.Contains("岁"))
                    {
                        trueAge = age.Replace("岁", "");
                    }
                    else
                    {
                        trueAge = age;
                    }
                    if (null != trueAge && int.Parse(trueAge) >= 60)
                    {
                        mazuiZhiKongTJ.LaoNianHuanZhe++;
                        mazuiZhiKongTJ.LaoNianHuanZheOperList.Add(patientLink);
                    }
                }
                catch (Exception e)
                {

                }
                if (pojo.Jnjmcc)
                {
                    mazuiZhiKongTJ.JingNeiJingMaiChuanCi++;
                    mazuiZhiKongTJ.JingNeiJingMaiChuanCiOperList.Add(patientLink);
                }
                if (pojo.Ndmcc)
                {
                    mazuiZhiKongTJ.NaoDongMaiChuanCi++;
                    mazuiZhiKongTJ.NaoDongMaiChuanCiOperList.Add(patientLink);
                }
                if (pojo.Qmqgbghssfs)
                {
                    mazuiZhiKongTJ.QiGuanShengSi++;  //全麻气管插管后声嘶发生
                    mazuiZhiKongTJ.QiGuanShengSiOperList.Add(patientLink);
                }
                if (pojo.Mzsshxfhmfs)
                {
                    mazuiZhiKongTJ.HunMi++; // 麻醉手术后新发昏迷发生
                    mazuiZhiKongTJ.HunMiOperList.Add(patientLink);
                }
                if (patientLink.Pacu.Pacudiwen)
                {
                    mazuiZhiKongTJ.DiTiWen++;  // PACU入室低体温发生
                    mazuiZhiKongTJ.DiTiWenOperList.Add(patientLink);
                }
                if (pojo.FjhzrICUfs)
                {
                    mazuiZhiKongTJ.ZhuanRuICU++;  // 非计划转入ICU发生
                    mazuiZhiKongTJ.ZhuanRuICUOperList.Add(patientLink);
                }
                if (pojo.Fjhecqgbg)
                {
                    mazuiZhiKongTJ.ErCiChaGuan++;  // 非计划二次插管次数
                    mazuiZhiKongTJ.ErCiChaGuanOperList.Add(patientLink);
                }
                if (pojo.Fjhecss)
                {
                    mazuiZhiKongTJ.NotPlan2ShouShu++;
                    mazuiZhiKongTJ.NotPlan2ShouShuOperList.Add(patientLink);
                }
                if (pojo.Fjhecmz)
                {
                    mazuiZhiKongTJ.NotPlan2Mazui++;
                    mazuiZhiKongTJ.NotPlan2MazuiOperList.Add(patientLink);
                }
                if (pojo.Fjhgbmzfs)
                {
                    mazuiZhiKongTJ.NotPlan2MazuiFangShi++;
                    mazuiZhiKongTJ.NotPlan2MazuiFangShiOperList.Add(patientLink);
                }
                if (pojo.Szsxsyfy)
                {
                    mazuiZhiKongTJ.ShuZhongShuXueShuYeFY++;//术中输血输液反应数
                    mazuiZhiKongTJ.ShuZhongShuXueShuYeFYOperList.Add(patientLink);
                }
                if (pojo.Shqgbgbc)
                {
                    mazuiZhiKongTJ.QiGuanBaChuCount++;  // 术后插管拔除次数
                    mazuiZhiKongTJ.QiGuanBaChuCountOperList.Add(patientLink);
                }
                if (pojo.PACUzryc)
                {
                    mazuiZhiKongTJ.ZhuanChuYanChi++;  // PACU转出延迟
                    mazuiZhiKongTJ.ZhuanChuYanChiOperList.Add(patientLink);
                }
                if (pojo.Twxh)
                {
                    mazuiZhiKongTJ.TiWaiXunHuan++;
                    mazuiZhiKongTJ.TiWaiXunHuanOperList.Add(patientLink);
                }
                if (pojo.ASAsw1)
                {
                    mazuiZhiKongTJ.ASA1Dead++;
                    mazuiZhiKongTJ.ASA1DeadOperList.Add(patientLink);
                }
                if (pojo.ASAsw2)
                {
                    mazuiZhiKongTJ.ASA2Dead++;
                    mazuiZhiKongTJ.ASA2DeadOperList.Add(patientLink);
                }
                if (pojo.ASAsw3)
                {
                    mazuiZhiKongTJ.ASA3Dead++;
                    mazuiZhiKongTJ.ASA3DeadOperList.Add(patientLink);
                }
                if (pojo.ASAsw4)
                {
                    mazuiZhiKongTJ.ASA4Dead++;
                    mazuiZhiKongTJ.ASA4DeadOperList.Add(patientLink);
                }
                if (pojo.ASAsw5)
                {
                    mazuiZhiKongTJ.ASA5Dead++;
                    mazuiZhiKongTJ.ASA5DeadOperList.Add(patientLink);
                }
                if (pojo.Ywsw)
                {
                    mazuiZhiKongTJ.YiWaiDead++;
                    mazuiZhiKongTJ.YiWaiDeadOperList.Add(patientLink);
                }
                if (pojo.Wyqysza)
                {
                    mazuiZhiKongTJ.WeiYuQiYiShi++;
                    mazuiZhiKongTJ.WeiYuQiYiShiOperList.Add(patientLink);
                }
                if (pojo.Ybhhdzdjd)
                {
                    mazuiZhiKongTJ.Spo2JiangDi++;
                    mazuiZhiKongTJ.Spo2JiangDiOperList.Add(patientLink);
                }
                if (pojo.Jsssycxyw)
                {
                    mazuiZhiKongTJ.UseCuiXingDrug++;
                    mazuiZhiKongTJ.UseCuiXingDrugOperList.Add(patientLink);
                }
                if (pojo.Ywywxyfhxdgz)
                {
                    mazuiZhiKongTJ.HuXiDaoGengZu++;//因误咽误吸引发呼吸道梗阻
                    mazuiZhiKongTJ.HuXiDaoGengZuOperList.Add(patientLink);
                }
                if (pojo.Qtfyqxgsj)
                {
                    mazuiZhiKongTJ.OtherFeiYuQiShiJian++;
                    mazuiZhiKongTJ.OtherFeiYuQiShiJianOperList.Add(patientLink);
                }
                if (pojo.Xffscg || pojo.Xffsbcg)
                {
                    mazuiZhiKongTJ.XinFeiFuSu++;
                    mazuiZhiKongTJ.XinFeiFuSuOperList.Add(patientLink);
                }
                if (pojo.Fscg)
                {
                    mazuiZhiKongTJ.FuSuChengGong++;
                    mazuiZhiKongTJ.FuSuChengGongOperList.Add(patientLink);
                }
                if (pojo.Stewardpf)
                {
                    mazuiZhiKongTJ.StewardBig4++;
                    mazuiZhiKongTJ.StewardBig4OperList.Add(patientLink);
                }
                if (pojo.Ssqkfl1)
                {
                    mazuiZhiKongTJ.OperType1++;
                    mazuiZhiKongTJ.OperType1OperList.Add(patientLink);
                }
                if (pojo.Ssqkfl2)
                {
                    mazuiZhiKongTJ.OperType2++;
                    mazuiZhiKongTJ.OperType2OperList.Add(patientLink);
                }
                if (pojo.Ssqkfl3)
                {
                    mazuiZhiKongTJ.OperType3++;
                    mazuiZhiKongTJ.OperType3OperList.Add(patientLink);
                }
                if (pojo.Ssqkfl4)
                {
                    mazuiZhiKongTJ.OperType4++;
                    mazuiZhiKongTJ.OperType4OperList.Add(patientLink);
                }
                if (pojo.Jczzsh)
                {
                    mazuiZhiKongTJ.QianCengZuZhi++;
                    mazuiZhiKongTJ.QianCengZuZhiOperList.Add(patientLink);
                }
                if (pojo.Sczzss)
                {
                    mazuiZhiKongTJ.ShenBuZuZhi++;
                    mazuiZhiKongTJ.ShenBuZuZhiOperList.Add(patientLink);
                }
                if (pojo.Qgss)
                {//器官手术
                    mazuiZhiKongTJ.QiGuan++;
                    mazuiZhiKongTJ.QiGuanOperList.Add(patientLink);
                }
                if (pojo.Kxnss)
                {
                    mazuiZhiKongTJ.QiangXiNei++;
                    mazuiZhiKongTJ.QiangXiNeiOperList.Add(patientLink);
                }
                if (pojo.Sgssjmcc)
                { //锁骨上深静脉穿刺
                    mazuiZhiKongTJ.SuoGuShangJingMaiChuanCi++;
                    mazuiZhiKongTJ.SuoGuShangJingMaiChuanCiOperList.Add(patientLink);
                }
                if (pojo.Sgxsjmcc)
                {
                    mazuiZhiKongTJ.SuoGuXiaJingMaiChuanCi++;
                    mazuiZhiKongTJ.SuoGuXiaJingMaiChuanCiOperList.Add(patientLink);
                }
                if (pojo.Gjmcc)
                {
                    mazuiZhiKongTJ.GuJingMaiChuanCi++;
                    mazuiZhiKongTJ.GuJingMaiChuanCiOperList.Add(patientLink);
                }
                if (pojo.Zbdmcc)
                {
                    mazuiZhiKongTJ.ZuBeiDongMaiChuanCi++;
                    mazuiZhiKongTJ.ZuBeiDongMaiChuanCiOperList.Add(patientLink);
                }
                if (pojo.Mzhtt)
                {
                    mazuiZhiKongTJ.MazuiHouTouTong++;
                    mazuiZhiKongTJ.MazuiHouTouTongOperList.Add(patientLink);
                }
                if (pojo.Cpyjm)
                {
                    mazuiZhiKongTJ.ChuanPoYingJiMo++;
                    mazuiZhiKongTJ.ChuanPoYingJiMoOperList.Add(patientLink);
                }
                if (pojo.Szzx)
                {
                    mazuiZhiKongTJ.ShuZhongZhiXiao++;
                    mazuiZhiKongTJ.ShuZhongZhiXiaoOperList.Add(patientLink);
                }
                if (pojo.Szyzdxy)
                {
                    mazuiZhiKongTJ.ShuZhongDiXueYa++;
                    mazuiZhiKongTJ.ShuZhongDiXueYaOperList.Add(patientLink);
                }
                if (pojo.Ycdmccyzbfzfs)
                {
                    mazuiZhiKongTJ.YouChuangDongMaiCCBingFa++;
                    mazuiZhiKongTJ.YouChuangDongMaiCCBingFaOperList.Add(patientLink);
                }
                if (pojo.Yxhs || pojo.Yxbhs)
                {
                    mazuiZhiKongTJ.YongXueShu++;
                    mazuiZhiKongTJ.YongXueShuOperList.Add(patientLink);
                }
                if (pojo.Yxhs)
                {
                    mazuiZhiKongTJ.YongXueHeLiShu++;
                    mazuiZhiKongTJ.YongXueHeLiShuOperList.Add(patientLink);
                }
                if (pojo.Sssylgy)
                {
                    mazuiZhiKongTJ.ShouShuShiYiLiaoGanYu++;
                    mazuiZhiKongTJ.ShouShuShiYiLiaoGanYuOperList.Add(patientLink);
                }
                if (pojo.Jxsx)
                {
                    mazuiZhiKongTJ.JiXingShiXue++;
                    mazuiZhiKongTJ.JiXingShiXueOperList.Add(patientLink);
                }
                if (pojo.Pgcsssj)
                {
                    mazuiZhiKongTJ.PouGongChanShouShu++;
                    mazuiZhiKongTJ.PouGongChanShouShuOperList.Add(patientLink);
                }
                if (pojo.Fssfwqgjzzss)
                {
                    mazuiZhiKongTJ.NotShouShuFanWeiQiGuanSunShang++;
                    mazuiZhiKongTJ.NotShouShuFanWeiQiGuanSunShangOperList.Add(patientLink);
                }
                if (pojo.Ghssfs)
                {
                    mazuiZhiKongTJ.GengGaiShouShuMethod++;
                    mazuiZhiKongTJ.GengGaiShouShuMethodOperList.Add(patientLink);
                }
                if (pojo.Ccdhzly)
                {
                    mazuiZhiKongTJ.ChuanCiDianHongZong++;
                    mazuiZhiKongTJ.ChuanCiDianHongZongOperList.Add(patientLink);
                }
                if (pojo.Dcbg)
                {
                    mazuiZhiKongTJ.DuoCiChaGuan++;
                    mazuiZhiKongTJ.DuoCiChaGuanOperList.Add(patientLink);
                }
                if (pojo.Dccc)
                {
                    mazuiZhiKongTJ.DuoCiChuanCi++;
                    mazuiZhiKongTJ.DuoCiChuanCiOperList.Add(patientLink);
                }
                if (pojo.Exot)
                {
                    mazuiZhiKongTJ.EXinOuTu++;
                    mazuiZhiKongTJ.EXinOuTuOperList.Add(patientLink);
                }
                if (pojo.Zthdza)
                {
                    mazuiZhiKongTJ.ZhiTiZangAi++;
                    mazuiZhiKongTJ.ZhiTiZangAiOperList.Add(patientLink);
                }
                if (pojo.Zdss)
                {
                    mazuiZhiKongTJ.ZhongDaShouShu++;
                    mazuiZhiKongTJ.ZhongDaShouShuOperList.Add(patientLink);
                }
                if (pojo.Qtyy)
                {
                    mazuiZhiKongTJ.QiTa++;
                    mazuiZhiKongTJ.QiTaOperList.Add(patientLink);
                }

                //总手术例数
                mazuiZhiKongTJ.OperationCount++;
                //麻醉方式,
                string mazuiMethod = patientLink.AnesthesiaRecord.Mzff;
                if (null == mazuiMethod || mazuiMethod.Equals(""))
                { //无麻醉

                }
                else
                {
                    ComplicatedMethodModel complicatedMethod = patientLink.AnesthesiaRecord.ComplicatedMethod;
                    //麻醉总数
                    mazuiZhiKongTJ.MaZuiCount++;
                    mazuiZhiKongTJ.MaZuiCountOperList.Add(patientLink);
                    if (mazuiMethod.Contains("插管全麻"))
                    {  //插管全麻
                        mazuiZhiKongTJ.ChaGuanQuanMaCount++;
                        mazuiZhiKongTJ.ChaGuanQuanMaCountOperList.Add(patientLink);
                    }
                    else if (mazuiMethod.Contains("非插管全麻"))
                    {  //非插管全麻
                        mazuiZhiKongTJ.FeiChaGuanQuanMaCount++;
                        mazuiZhiKongTJ.FeiChaGuanQuanMaCountOperList.Add(patientLink);
                    }
                    else if (mazuiMethod.Contains("椎管内麻醉"))
                    {  //椎管内麻醉
                        mazuiZhiKongTJ.ZhuiGuanNeiMaZauiCount++;
                        mazuiZhiKongTJ.ZhuiGuanNeiMaZauiCountOperList.Add(patientLink);
                    }
                    else if (mazuiMethod.Contains("插管全麻+椎管内麻醉"))
                    {  //插管全麻+椎管内麻醉
                        mazuiZhiKongTJ.ChaGuanQuanMaAndZhuiGuan++;
                        mazuiZhiKongTJ.ChaGuanQuanMaAndZhuiGuanOperList.Add(patientLink);
                    }
                    else if (mazuiMethod.Contains("插管全麻+椎管内麻醉"))
                    { //神经阻滞麻醉
                        mazuiZhiKongTJ.ShenJingZuZhi++;
                        mazuiZhiKongTJ.ShenJingZuZhiOperList.Add(patientLink);
                    }
                    else if (mazuiMethod.Equals("静脉麻醉"))
                    {
                        mazuiZhiKongTJ.JingMaiMaZuiConut++;
                        mazuiZhiKongTJ.JingMaiMaZuiConutOperList.Add(patientLink);
                    }
                    else
                    {  //其它麻醉
                        mazuiZhiKongTJ.QiTaMaZuiCount++;
                        mazuiZhiKongTJ.QiTaMaZuiCountOperList.Add(patientLink);
                    }
                    if (mazuiMethod.Contains("复合麻醉"))
                    {  //复合麻醉
                        mazuiZhiKongTJ.FuHeMaZuiCount++;
                        mazuiZhiKongTJ.FuHeMaZuiCountOperList.Add(patientLink);
                    }
                }
                //是否急诊
                if (patientLink.Application.Type != null
                        && patientLink.Application.Type.Equals(Constants.OR_TYPE_URGENT))
                {
                    mazuiZhiKongTJ.JiZhen++; //急诊
                    mazuiZhiKongTJ.JiZhenOperList.Add(patientLink);
                }
                //ASA分级
                string asa = patientLink.AnesthesiaRecord.Asa.Level;
                if (Constants.ASA_1.Equals(asa) || "I".Equals(asa))
                {
                    mazuiZhiKongTJ.ASA1++;
                    mazuiZhiKongTJ.ASA1OperList.Add(patientLink);
                }
                else if (Constants.ASA_2.Equals(asa) || "II".Equals(asa))
                {
                    mazuiZhiKongTJ.ASA2++;
                    mazuiZhiKongTJ.ASA2OperList.Add(patientLink);
                }
                else if (Constants.ASA_3.Equals(asa) || "III".Equals(asa))
                {
                    mazuiZhiKongTJ.ASA3++;
                    mazuiZhiKongTJ.ASA3OperList.Add(patientLink);
                }
                else if (Constants.ASA_4.Equals(asa) || "IV".Equals(asa))
                {
                    mazuiZhiKongTJ.ASA4++;
                    mazuiZhiKongTJ.ASA4OperList.Add(patientLink);
                }
                else if (Constants.ASA_5.Equals(asa) || "V".Equals(asa))
                {
                    mazuiZhiKongTJ.ASA5++;
                    mazuiZhiKongTJ.ASA5OperList.Add(patientLink);
                }
                else if (Constants.ASA_6.Equals(asa) || "VI".Equals(asa))
                {
                    mazuiZhiKongTJ.ASA6++;
                    mazuiZhiKongTJ.ASA6OperList.Add(patientLink);
                }
                //术后镇痛、PCA
                string pca = patientLink.AnesthesiaRecord.PCA;
                if (null == pca)
                { //打补丁，2种记录PCA数据的字段
                    bool shuHouZhenTong = false;
                    if (patientLink.AnesthesiaRecord.PCIA)
                    {
                        mazuiZhiKongTJ.JingMaiPCA++;
                        mazuiZhiKongTJ.JingMaiPCAOperList.Add(patientLink);
                        shuHouZhenTong = true;
                    }
                    else if (patientLink.AnesthesiaRecord.PCEA)
                    {
                        mazuiZhiKongTJ.YingMoWaiPCA++;
                        mazuiZhiKongTJ.YingMoWaiPCAOperList.Add(patientLink);
                        shuHouZhenTong = true;
                    }
                    else if (patientLink.AnesthesiaRecord.PCNA)
                    {
                        mazuiZhiKongTJ.ShengJingCongPCA++;
                        mazuiZhiKongTJ.ShengJingCongPCAOperList.Add(patientLink);
                        shuHouZhenTong = true;
                    }
                    else if (patientLink.AnesthesiaRecord.PCSA)
                    {
                        mazuiZhiKongTJ.PiXiaPCA++;
                        mazuiZhiKongTJ.PiXiaPCAOperList.Add(patientLink);
                        shuHouZhenTong = true;
                    }
                    if (shuHouZhenTong)
                    {
                        mazuiZhiKongTJ.ShuHouZhenTong++;
                        mazuiZhiKongTJ.ShuHouZhenTongOperList.Add(patientLink);
                    }
                }
                if (null != pca && !pca.Equals("无"))
                {
                    mazuiZhiKongTJ.ShuHouZhenTong++;
                    mazuiZhiKongTJ.ShuHouZhenTongOperList.Add(patientLink);

                    if (pca.Equals("PCIA"))
                    {
                        mazuiZhiKongTJ.JingMaiPCA++;
                        mazuiZhiKongTJ.JingMaiPCAOperList.Add(patientLink);
                    }
                    else if (pca.Equals("PCSA"))
                    {
                        mazuiZhiKongTJ.PiXiaPCA++;
                        mazuiZhiKongTJ.PiXiaPCAOperList.Add(patientLink);
                    }
                    else if (pca.Equals("PCEA"))
                    {
                        mazuiZhiKongTJ.YingMoWaiPCA++;
                        mazuiZhiKongTJ.YingMoWaiPCAOperList.Add(patientLink);
                    }
                    else if (pca.Equals("PCNA"))
                    {
                        mazuiZhiKongTJ.ShengJingCongPCA++;
                        mazuiZhiKongTJ.ShengJingCongPCAOperList.Add(patientLink);
                    }
                    else
                    {
                        mazuiZhiKongTJ.OtherPCA++;
                        mazuiZhiKongTJ.OtherPCAOperList.Add(patientLink);
                    }
                }

                //术后去向
                string patQuWang = patientLink.AnesthesiaRecord.Brqw;
                if (Constants.ICU.Equals(patQuWang) || patQuWang == null)
                {
                    mazuiZhiKongTJ.ICUCount++;
                    mazuiZhiKongTJ.ICUCountOperList.Add(patientLink);
                }
                else if (Constants.PACU.Equals(patQuWang))
                {
                    mazuiZhiKongTJ.PACUCount++;
                    mazuiZhiKongTJ.PACUCountOperList.Add(patientLink);
                }

                //输血、自体血

                try
                {
                    if (mazuiZhiKongTJ.ZiTiXueShuZhu > 400)
                    {
                        mazuiZhiKongTJ.ZiTiXueShuZhu++;
                        mazuiZhiKongTJ.ZiTiXueShuZhuOperList.Add(patientLink);
                    }
                }
                catch (Exception e)
                {
                    //System.out.println(e.Message);
                }

            }


            List<QualityStatisticsModel> dataList = new List<QualityStatisticsModel>();
            foreach (QualityStatisticsModel one in mapNewZhiKong.Values)
            {
                dataList.Add(one);
            }
            return dataList;
        }
    }
}
